/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataConverters.utils;

import java.io.Serializable;

/**
 *
 * @author Nobody
 */
public class DataFormulaObject implements Serializable {

    private static final long serialVersionUID = -403250971215465050L;
    private int xIndex;
    private int yIndex;
    private String formula;
    private double data;
    private boolean isFormula;
    private boolean plainString;

    public DataFormulaObject(int xIndex, int yIndex) {
        this.xIndex = xIndex;
        this.yIndex = yIndex;
    }

    public DataFormulaObject(int xIndex, int yIndex, String formula) {
        this(xIndex, yIndex);
        this.plainString = true;
        this.formula = formula;
        setIsFormula();
    }

    public DataFormulaObject(int xIndex, int yIndex, double data) {
        this(xIndex, yIndex);
        this.data = data;
        isFormula = false;
        plainString = false;
    }

    public DataFormulaObject(int xIndex, int yIndex, String formula, double formulaValue) {
        this(xIndex, yIndex, formulaValue);
        this.plainString = false;
        if (!formula.startsWith("=")) {
            formula = "=" + formula;
        }
        this.formula = formula;
        setIsFormula();
    }

    private void setIsFormula() {
        isFormula = !plainString;
    }

   
    public double getDataAsDouble() {
        return data;
    }

    public String getFormula() {
        return formula;
    }

    public boolean isFormula() {
        return isFormula;
    }

    public boolean isPlainString() {
        return plainString;
    }

    public int getxIndex() {
        return xIndex;
    }

    public int getyIndex() {
        return yIndex;
    }

    public Object getStringValue() {
        if(plainString){
            return formula;
        }else{
            return null;
        }
    }
}
